package org.hope.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author Thilanka
 */
public class ConnectionManager
{

	private ConnectionManager()
	{

	}

	public static Connection getConnection() throws Exception
	{
		String url = "jdbc:mysql://localhost:3306/";
		String dbName = "hope_smart";
		String driver = "com.mysql.jdbc.Driver";
		String userName = "root";
		String password = "hope321";

		Class.forName( driver ).newInstance();
		Connection conn = DriverManager.getConnection( url + dbName, userName, password );

		return conn;
	}

	public static void close( Connection con )
	{
		try
		{
			if ( con != null && !con.isClosed() )
			{
				con.close();
			}
		}
		catch ( SQLException e )
		{
			e.printStackTrace();
		}
	}

	public static void close( ResultSet rs )
	{
		try
		{
			if ( rs != null )
			{
				rs.close();
			}
		}
		catch ( SQLException e )
		{
			e.printStackTrace();
		}
	}

	public static void close( Statement statement )
	{
		try
		{
			if ( statement != null )
			{
				statement.close();
			}
		}
		catch ( SQLException e )
		{
			e.printStackTrace();
		}
	}

}
